<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>js创建SVG</title>
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      background-color: #000;
      margin: 0;
    }

    #div1 {
      width: 600px;
      height: 600px;
      background-color: #fff;
      margin: 0 auto;
    }
  </style>
  <script>
    window.onload = function () {

      let oParent = document.getElementById("div1");

      // 命名空间
      let svgNS = "http://www.w3.org/2000/svg";
      let oSvg = document.createElementNS(svgNS, "svg");

      oSvg.setAttribute('xmlns', svgNS);
      oSvg.setAttribute('width', "100%");
      oSvg.setAttribute('height', "100%");

      oParent.appendChild(oSvg);
    }
  </script>
</head>

<body>
  <div id='div1'></div>
</body>

</html>